﻿package Classes.GameUtils
{
	
	import com.greensock.TweenLite;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	/**
	 *管理好友，与建筑面板收缩的按扭类 ---专用
	 * @author upstream
	 * 
	 */	
	public class HideSlideFastenerBtn
	{
		public var clBig1:MovieClip;
		public var clBig2:MovieClip;
		public var clBig3:MovieClip;
		
		public var clSmall1:MovieClip;
		public var clSmall2:MovieClip;
		public var clSmall3:MovieClip;
		
		
		public var tl:MovieClip;
		public var tld:MovieClip;
		
		public var targetUI:Sprite;		//按扭UI
		public var clickCL:String;			//点击了小齿轮还是大齿轮
		public var isMove:Boolean=false;  //正在动
		public function HideSlideFastenerBtn(sp:Sprite)
		{
			this.targetUI	=	sp;
			HideMainPanelBtn();
		}
		
		/**
		 *上下拉按扭 
		 * 
		 */
		public function HideMainPanelBtn():void
		{

			
			clSmall1	=	this.targetUI.getChildByName("clSmall1") as MovieClip;
			clBig1		=	this.targetUI.getChildByName("clBig1")	as MovieClip;
			tl			=	this.targetUI.getChildByName("tl")	as MovieClip;

			clSmall2	=	this.targetUI.getChildByName("clSmall2") as MovieClip;
			clBig2		=	this.targetUI.getChildByName("clBig2")	as MovieClip;
			tld			=	this.targetUI.getChildByName("tld")	as MovieClip;
			
			clSmall3	=	this.targetUI.getChildByName("clSmall3") as MovieClip;
			clBig3		=	this.targetUI.getChildByName("clBig3")	as MovieClip;
			
			
//			clBig1.visible		= 	true;
//			clSmall1.visible	= 	true;
//			tl.visible			= 	true;
//			
//			clBig2.visible		= 	false;
//			clSmall2.visible	= 	false;
//			tld.visible			= 	false;
//			
//			clBig3.visible		= 	false;
//			clSmall3.visible	= 	false;
			setNormal();
			
			this.clBig2.addEventListener(MouseEvent.MOUSE_OVER, function(e:Event):void{
				setClMove();
			});
			
			this.clBig2.addEventListener(MouseEvent.MOUSE_OUT, function(e:Event):void{
				setNormal();
			});
			
			
			//小齿轮
			this.clSmall2.addEventListener(MouseEvent.MOUSE_OVER, function(e:Event):void{
				setClMove();
			});
			
			this.clSmall2.addEventListener(MouseEvent.MOUSE_OUT, function(e:Event):void{
				setNormal();
			});
			
			
			this.clBig2.addEventListener(MouseEvent.CLICK, function(e:Event):void{
				if(isMove)return;
				clickCL	=	"big";
				targetUI.dispatchEvent( new Event("clickCL", true));
			});
			this.clSmall2.addEventListener(MouseEvent.CLICK, function(e:Event):void{
				if(isMove)return;
				clickCL	=	"small";
				targetUI.dispatchEvent( new Event("clickCL", true));
			});
		}
		
		/**
		 *正常的状态 
		 * 
		 */
		public function setNormal():void
		{
			if(isMove)return;
			
			clBig1.visible		= 	false;
			clSmall1.visible	= 	false;
			tl.visible			= 	true;
			
			clBig2.visible		= 	true;
			clSmall2.visible	= 	true;
			tld.visible			= 	false;
			clBig2.gotoAndStop(1);
			clSmall2.gotoAndStop(1);
			
			clBig3.visible		= 	false;
			clSmall3.visible	= 	false;
		}
		
		
		/**
		 *移动的状态 
		 * 
		 */
		public function setMove():void
		{	
			if(isMove)return;
			
			isMove 	=	true;
			
			clBig1.visible		= 	false;
			clSmall1.visible	= 	false;
			tl.visible			= 	false;
			
			clBig2.visible		= 	false;
			clSmall2.visible	= 	false;
			tld.visible			= 	true;
			
			clBig3.visible		= 	true;
			clSmall3.visible	= 	true;
			
			var t:Timer	=	new Timer(600,1);
			t.addEventListener(TimerEvent.TIMER, function(e:Event):void{

				setNoMove();	
			});
			
			t.start();
		}
		
		/**
		 *非移动的状态 
		 * 
		 */
		public function setNoMove():void
		{	
			if(!isMove)return;
			isMove 	=	false;
			setNormal();
		}
		
		/**
		 *两个齿轮在小动
		 * 
		 */
		public function setClMove():void
		{
			if(isMove)return;
			
			clBig1.visible		= 	false;
			clSmall1.visible	= 	false;
			tl.visible			= 	true;
			
			clBig2.visible		= 	true;
			clSmall2.visible	= 	true;
			tld.visible			= 	false;
			clBig2.gotoAndPlay(1);
			clSmall2.gotoAndPlay(1);
			
			clBig3.visible		= 	false;
			clSmall3.visible	= 	false;
		}
	}
}